<?php

namespace App\Services\Admin;

use App\Models\GoodsOrder as GoodsOrderModel;

class Order extends Base
{
    public static function lists()
    {
        $input = request()->all();

        $where = [];

        if(isset($input['is_receive'])){
            if($input['is_receive'] != '')$where[] = ['is_receive', $input['is_receive']];
        }

        $result = GoodsOrderModel::with(['goods','user']);

        if(!empty($input['sear_value'])){
            $result = $result->whereHas('user',function ($query)use($input){
                $where[] = ['name','like','%'.$input['sear_value'].'%'];
                $where[] = ['phone','like',$input['sear_value'].'%','OR'];
                $query->where($where);
            });
        }

        return $result->where($where)->orderBy('id', 'desc')->paginate(15);
    }

    /**
     * 领取奖品
     * @param $id
     */
    public static function receive($id)
    {
        $goods_order = GoodsOrderModel::find($id);
        $goods_order->is_receive = 1;
        $goods_order->save();
    }
}
